// 封装所有用户相关模块
import request from '@/utils/request.js'
// 组件中通过this.$store 访问vuex 的实例
// 在普通函数中 通过import引入store/index.js 能够访问vuex的实例
// import store from '@/store'

/**
 *  登录请求
 * @param {Object} data {mobile:'',code:''}
 */

export const login = data => {
  // return出去一个promise对象用async和await接收
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data
  })
}

/**
 *发送验证码
 * @param {*} mobile
 * @returns
 */
export const sendCode = mobile => {
  // return出去一个promise对象用async和await接收
  return request({
    method: 'GET',
    url: `/v1_0/sms/codes/${mobile}`
  })
}

/**
 *获取用户信息
 * @returns
 */
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
  })
}

/**
 *获取用户频道列表
 * @returns
 */
export const getUseChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

/**
 *关注用户
 * @param {*} id 用户id
 * @returns
 */
export const addUserFollow = id => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: id
    }
  })
}

/**
 *取消关注用户
 * @param {*} id 用户id
 * @returns
 */
export const deleteUserFollow = id => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + id
  })
}

/**
 * 获取用户信息
 * @returns
 */
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/**
 * 编辑用户资料
 * @param {Object} data {name:'',photo:'',gender:''}
 * @returns
 */
export const editUserInfo = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

export const editUserAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
